{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b507895f-f2af-496d-b1d2-1895b58a9372",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-11-23T07:14:47.654762Z",
     "iopub.status.busy": "2021-11-23T07:14:47.654233Z",
     "iopub.status.idle": "2021-11-23T07:14:47.658433Z",
     "shell.execute_reply": "2021-11-23T07:14:47.657903Z",
     "shell.execute_reply.started": "2021-11-23T07:14:47.654726Z"
    }
   },
   "outputs": [],
   "source": [
    "from simple_pid import PID \n",
    "import time\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "04a95514-1af7-4866-8c41-fefe304b34a0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-11-23T07:14:56.693461Z",
     "iopub.status.busy": "2021-11-23T07:14:56.693063Z",
     "iopub.status.idle": "2021-11-23T07:14:56.698152Z",
     "shell.execute_reply": "2021-11-23T07:14:56.697393Z",
     "shell.execute_reply.started": "2021-11-23T07:14:56.693428Z"
    }
   },
   "outputs": [],
   "source": [
    "class heater:     \n",
    "    def __init__(self):         \n",
    "        self.temp = 25     \n",
    "    \n",
    "    def update(self, power, dt):         \n",
    "        if power > 0:                           \n",
    "            #加热时房间温度随变量power和时间变量dt 的变化             \n",
    "            self.temp += 2 * power * dt         \n",
    "            #表示房间的热量损失         \n",
    "            self.temp -= 0.5 * dt         \n",
    "    \n",
    "        return self.temp "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "e4970fe4-825a-4a96-b1ce-696a42b0e49b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-11-23T07:15:45.794991Z",
     "iopub.status.busy": "2021-11-23T07:15:45.794387Z",
     "iopub.status.idle": "2021-11-23T07:16:08.167073Z",
     "shell.execute_reply": "2021-11-23T07:16:08.166409Z",
     "shell.execute_reply.started": "2021-11-23T07:15:45.794948Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoA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d4MuBYY6+7jzOw6glkqC4ExBJO09SW4ebAB+Ly77zGz0QTTuJcCdcDX3f3tbH8Jkfao+0gkfXOA9e4+AfjeMZ+NA64EzgP+D1AXTk73V+C/h9vMA25y93OB2cAvslG0SEeopSCSGc+Hz604YGb7gCfD9W8AZ4ez1X4MeDyYpgeAk7Jfpkj7FAoimdHQ6nVzq/fNBP8/ywFqwlaGSLel7iOR9B0AijqzY/gsi41mdjUEs9ia2TmZLE4kExQKImly993Ay+ED1H/aiUN8FZhpZq8Db5KAx8JKz6NLUkVEJEUtBRERSVEoiIhIikJBRERSFAoiIpKiUBARkRSFgoiIpCgUREQk5f8D7y5CD4RAL+AAAAAASUVORK5CYII=",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "if __name__ == '__main__': \t\n",
    "    #将创建的模型写进主函数     \n",
    "    heater = heater()     \n",
    "    temp = heater.temp \t\n",
    "    #设置PID的三个参数，以及限制输出     \n",
    "    pid = PID(2, 0.01, 0.1, setpoint=temp)     \n",
    "    pid.output_limits = (0, None)\n",
    "    pid.sample_time = 0.01\t\n",
    "    #用于设置时间参数     \n",
    "    start_time = time.time()     \n",
    "    last_time = start_time \t\n",
    "    #用于输出结果可视化     \n",
    "    setpoint, y, x = [], [], [] \t\n",
    "    #设置系统运行时间     \n",
    "    while time.time() - start_time < 10:         \t        \t\n",
    "        #设置时间变量dt         \n",
    "        current_time = time.time()         \n",
    "        dt = (current_time - last_time)                  \n",
    "        #变量temp在整个系统中作为输出，变量temp与理想值之差作为反馈回路中的输入，通过反馈回路调节变量power的变化。\n",
    "        power = pid(temp)         \n",
    "        temp = heater.update(power, dt)                  \n",
    "        #用于输出结果可视化         \n",
    "        x += [current_time - start_time]         \n",
    "        y += [temp]         \n",
    "        setpoint += [pid.setpoint] \t\t\n",
    "        #用于变量temp赋初值         \n",
    "        if current_time - start_time > 0:             \n",
    "            pid.setpoint = 100          \n",
    "        last_time = current_time \t \t\n",
    "    #输出结果可视化     \n",
    "    plt.plot(x, setpoint, label='target')     \n",
    "    plt.plot(x, y, label='PID')     \n",
    "    plt.xlabel('time')     \n",
    "    plt.ylabel('temperature')     \n",
    "    plt.legend()     \n",
    "    plt.show() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "d7c6130e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2.9802322387695312e-05,\n",
       " 1.9073486328125e-06,\n",
       " 1.430511474609375e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 1.6689300537109375e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 1.430511474609375e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.6689300537109375e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.430511474609375e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 2.1457672119140625e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 1.6689300537109375e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 1.6689300537109375e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 5.0067901611328125e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.430511474609375e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.6689300537109375e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.9073486328125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 1.430511474609375e-06,\n",
       " 1.1920928955078125e-06,\n",
       " 9.5367431640625e-07,\n",
       " 9.5367431640625e-07,\n",
       " 1.1920928955078125e-06,\n",
       " 1.1920928955078125e-06]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "div = []\n",
    "for i in range(100):\n",
    "    div.append(x[i+1]-x[i])\n",
    "div"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ac48b14",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "80297a49353e01fd30519dbbd85f9d444d6210a697f633f8361ee088cad82092"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
